package teacher.action;

import java.io.UnsupportedEncodingException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import teacher.bean.Paper;
import teacher.bean.Teacher;
import teacher.page.Page;
import teacher.page.PageUtil;
import teacher.service.paper;
import teacher.service.treatise;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class searchPap extends ActionSupport{
	
	private List<Paper> papers;
	private String vague;
	private int currentPage;
	private String method;

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public String getMethod() {
		return method;
	}

	public void setMethod(String method) {
		this.method = method;
	}

	public String getVague() {
		return vague;
	}

	public void setVague(String vague) {
		this.vague = vague;
	}

	public List<Paper> getPapers() {
		return papers;
	}

	public void setPapers(List<Paper> papers) {
		this.papers = papers;
	}
	
	public String execute()
	{
		HttpServletRequest request=ServletActionContext.getRequest();
		Teacher tea=(Teacher)request.getSession().getAttribute("teacher");
		ActionContext.getContext().put("flag", 2);
	    ActionContext.getContext().put("name", this.getVague());
	    
	    if(method!=null && method.equals("get")){
	    	try {
	    		this.vague = new String(vague.getBytes("iso8859-1"),"UTF-8");
	    	} catch (UnsupportedEncodingException e) {    		  
	    		e.printStackTrace();
	    	}
	    }
	    
	    ActionContext.getContext().put("name11", this.getVague());	    
	      
	    // 获得记录数
	 	int totalCount = new paper().getCountPaperTeaVague(vague, tea);
	 	// 设置分页信息
	 	Page page = PageUtil.createPage(10, totalCount, currentPage);
		papers=new paper().selectVaguePaperTeaPage(vague, tea, page);
		request.setAttribute("papers",papers);
		request.setAttribute("page",page);
		return SUCCESS;
	}

}
